﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System
{
    public static class ConvertType
    {
        public static int? AsInt(this object ob)
        {
            try
            {
                if (ob == null)
                    return null;
                else
                    return Convert.ToInt32(ob);
            }
            catch
            {
                return null;
            }
        }

        public static int? AsInt(this string str)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(str))
                    return null;
                else
                    return Convert.ToInt32(str);
            }
            catch
            {
                return null;
            }
        }

        public static DateTime? AsDateTime(this string str)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(str))
                    return null;
                else
                    return Convert.ToDateTime(str);
            }
            catch
            {
                return null;
            }
        }
    }
}
